package com.wechat.shopping.mall.util;

import java.io.Serializable;

/**
 * 项目统一返回类型包装
 */
public class ResponseMessage<T> implements Serializable {

    private static final long serialVersionUID = 8585767928657727777L;

    /**
     * 成功标志
     */
    private boolean success;

    /**
     * 提示信息
     */
    private String message;

    /**
     * 返回数据
     */
    private T data;

    /**
     * 响应码
     */
    private int code;

    public ResponseMessage setCode(int code) {
        this.code = code;
        return this;
    }

    public ResponseMessage(T data) {
        this.data = data;
        this.success = true;
        this.message = "OK";
    }

    public ResponseMessage(boolean success, String message) {
        this.success = success;
        this.message = message;
    }

    public ResponseMessage(boolean success, T data) {
        this.data = data;
        this.success = true;
        this.message = "OK";
    }

    public ResponseMessage(boolean success, String message, T data) {
        this.success = success;
        this.message = message;
        this.data = data;
    }

    public static ResponseMessage ok() {
        return ok(null);
    }

    public static ResponseMessage ok(Object data) {
        return new ResponseMessage(true, data);
    }

    public static ResponseMessage error(String message) {
        return new ResponseMessage(message);
    }

    public static ResponseMessage error(String message, int code) {
        return new ResponseMessage(message).setCode(code);
    }


}
